﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace Vit.Data
{
    public class SqlWhere : SqlClause
    {
        public List<SqlCondition> Conditions { get; set; }

        public IEnumerable<DbParameter> Parameters
        {
            get
            {
                foreach (var condition in Conditions)
                {
                    yield return new SqlParameter()
                    {
                        ParameterName = condition.ParameterName,
                        DbType = condition.DataType,
                        Direction = ParameterDirection.Input,
                        Value = condition.Value
                    };
                }
            }
        }

        public override string ToSql()
        {
            StringBuilder sb = new StringBuilder();
            foreach (var condition in Conditions)
                sb.Append(condition.ToSql());
            return sb.ToString();
        }
    }
}
